//
//  WBHomeViewController.swift
//  新浪微博
//
//  Created by shanlin on 2017/8/9.
//  Copyright © 2017年 shanlin. All rights reserved.
//

import UIKit

//定义全局常量,尽量用private 修饰, 否则到处可以访问
//private let cellId = "cellId"
let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {
  
    //列表视图模型
    fileprivate lazy var listViewModel = WBStatusViewListModel()
    //加载数据
    override func loadData() {
        
//        WBNetworkManager.shared.statusList { (list, isSuccess) in
////            print(list)
//            
//           
//            
//        }
        
        listViewModel.loadStatus(pullup: self.isPullup) { (isSuccess, shouldRefresh) in
            print(isSuccess)
            print("加载数据结束\(self.listViewModel.StatusList.last?.text)")
            self.refreshControl?.endRefreshing()
            self.isPullup = false
            //刷新表格
            if shouldRefresh {
                self.tableView?.reloadData()
            }
            
        }
        
        
        
    
    }
    

    
    
    @objc fileprivate func showFriends(){
        print(#function)
        
        let vc = WBDemoViewController()
//        vc.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(vc, animated: true)
        
    }

    

}

//MARK -表格数据源方法
extension WBHomeViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print(listViewModel.StatusList.count)
        return listViewModel.StatusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //1.取cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        //设置cell
        cell.textLabel?.text = listViewModel.StatusList[indexPath.row].text
        return cell
    }
    
}
//MARK - 设置界面
extension WBHomeViewController {
    override func setupTableView() {
        super.setupTableView()
        //设置导航栏按钮
        navItem.leftBarButtonItem = UIBarButtonItem.init(title: "好友", fontSize: 16, target: self, action: #selector(showFriends))
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
